<?php
namespace Home\Model;

class BloodModel extends CommonModel{
    
    /**
     * 更新用户某一天的血压均值
     * $uid 用户id
     * $create_date 更新这一天的血压
     */
    public function updateBloodAverage($uid,$create_date){
        $list = array();
        $bloodLowSum = 0;$bloodHighSum = 0;
        $list = $this->where(array('uid'=>$uid,'create_date'=>$create_date))->select();
        foreach($list as $v){
            $bloodLowSum  += $v['low'];
            $bloodHighSum += $v['high'];
        }
        $listCount = count($list);
        $low_average = round(($bloodLowSum/$listCount),0);
        $high_average = round(($bloodHighSum/$listCount),0);
        $this->where(array('uid'=>$uid,'create_date'=>$create_date))->save(array(
            'low_average'=>$low_average,'high_average'=>$high_average
        ));
    }
    
}